package com.design03_behavioral.pattern20_memento.example02;

/**
 * @ClassName MainApp
 * @Description TODO
 * @Author 22963
 * @DATE 2023/9/10 13:19
 */
public class MainApp {

    public static void main(String[] args) throws InterruptedException {

        //最初所持的金钱数
        Player player = new Player(100);

        Memento memento = player.createMemento();

        for (int i = 0; i < 100; i++) {
            //显示扔骰子的次数
            System.out.println("======"+ i);

            //显示当前状态
            System.out.println("当前状态: "+ player);

            //开启游戏
            player.yacht();
            System.out.println("所持有的金钱为: " + player.getMoney() + " 元");

            //决定如何操作Menento  提供了一个后门,能让用户继续操作
            if ((player.getMoney()>memento.getMoney())) {
                System.out.println("赚到金币,保存当前状态,继续游戏");
                memento = player.createMemento();
            }else if (player.getMoney()<memento.getMoney()/2){
                System.out.println("所持金币不多了,将游戏恢复到初 始状态!");
                player.restore(memento);
            }

            Thread.sleep(1000);
            System.out.println("");


        }

    }

}
